/**
 * Created by Administrator on 2017/3/13 0013.
 */
ControlCenter={
    Create:function(){
        var cc={};
        var whole=new PIXI.DisplayObjectContainer();
        var pageWhole=new PIXI.DisplayObjectContainer();
        var page1,page2,page3,page4,page5,page6,page7;
        cc.Go=function(){
            Music["music1"].play();


            whole.addChild(pageWhole);






            page7=Page7.Create();
            pageWhole.addChild(page7.ReturnWhole());
            page6=Page6.Create();
            pageWhole.addChild(page6.ReturnWhole());




            page1=Page1.Create();
            pageWhole.addChild(page1.ReturnWhole());
            page2=Page2.Create();
            pageWhole.addChild(page2.ReturnWhole());
            page3=Page3.Create();
            pageWhole.addChild(page3.ReturnWhole());
            page4=Page4.Create();
            pageWhole.addChild(page4.ReturnWhole());
            page5=Page5.Create();
            pageWhole.addChild(page5.ReturnWhole());


            var arr_page=[page5,page6,page7];
            // Scroller.create(pageWhole,740,1136,"hor",arr_page);

            var sc=Scroller.create(pageWhole,740,1136,"ver",arr_page);

                // sc.bl_canMove=true;


            document.addEventListener('Game_ScrollComplete',scrollCompleteHander);
            document.addEventListener('Game_ScrollStart',scrollStartHander);
            function scrollStartHander(e) {
                console.log('out',e.detail);
                arr_page[e.detail].Out();
            }
            function scrollCompleteHander(e) {
                console.log('In',e.detail);
                arr_page[e.detail].In();
                if(e.detail==1){
                    console.log("!!!!!!!!!");
                    bl_guagua=false;
                }
                else if(e.detail==0){
                    bl_guagua=true;
                }
            }

            pageNum=1;
            var bl_canclick=false;
            var bl_guagua=true;

            setTimeout(function(){
                bl_canclick=true;
            },2900)


            var mouseY=0;
            var mouseAfterY=0;

            document.addEventListener("mousedown",function(e){
                mouseY=e.clientY;
            })
            document.addEventListener("mousemove",function(e) {
                mouseAfterY=e.clientY;
            })
            document.addEventListener("mouseup",function(e){
                if(bl_canclick&&bl_guagua) {
                    bl_canclick=false;

                    if(mouseY-mouseAfterY<50) {
                        console.log("left");
                        pageNum--;

                        switch (pageNum) {
                            case 1:
                                page1.In();
                                page2.end();
                                break;
                            case 2:
                                page2.start();
                                setTimeout(function () {
                                    page3.end();
                                }, 500)
                                break;
                            case 3:
                                page3.start();
                                setTimeout(function () {
                                    page4.end();
                                }, 500)
                                break;
                            case 4:
                                page4.start();
                                setTimeout(function () {
                                    page5.end();
                                }, 500)
                                sc.bl_canMove=false;
                                break;
                        }
                        if(pageNum<=1){
                            pageNum=1;
                            bl_canclick=true;
                        }
                        else{
                            setTimeout(function(){
                                bl_canclick=true;
                            },2500)
                        }
                    }
                    else if(mouseY-mouseAfterY>-50)  {
                        pageNum++;

                        console.log("right");
                        switch (pageNum) {
                            case 2:
                                page1.Out();
                                page2.start();
                                break;
                            case 3:
                                // page2.end();
                                setTimeout(function () {
                                    page3.start();
                                }, 500)
                                break;
                            case 4:
                                // page3.end();
                                setTimeout(function () {
                                    page4.start();
                                }, 500)
                                break;
                            case 5:
                                // page4.end();
                                setTimeout(function () {
                                    page5.start();
                                }, 500)

                                setTimeout(function(){
                                    sc.bl_canMove=true;
                                },2400)
                                break;
                        }
                        if(pageNum>=5){
                            pageNum=5;
                            bl_canclick=true;
                        }
                        else{
                            setTimeout(function(){
                                bl_canclick=true;
                            },2500)
                        }
                    }
                }
            })




            document.addEventListener("touchstart",function(e){
                mouseY=e.touches[0].pageY;
            })
            document.addEventListener("touchmove",function(e) {
                mouseAfterY=e.touches[0].pageY;
            })
            document.addEventListener("touchend",function(e){
                if(bl_canclick&&bl_guagua) {
                    bl_canclick=false;

                    if(mouseY-mouseAfterY<50) {
                        console.log("left");
                        pageNum--;

                        switch (pageNum) {
                            case 1:
                                page2.end();
                                page1.In();
                                break;
                            case 2:

                                page2.start();
                                setTimeout(function () {
                                    page3.end();
                                }, 500)
                                break;
                            case 3:
                                page3.start();
                                setTimeout(function () {
                                    page4.end();
                                }, 500)
                                break;
                            case 4:
                                page4.start();
                                setTimeout(function () {
                                    page5.end();
                                }, 500)
                                sc.bl_canMove=false;
                                break;
                        }
                        if(pageNum<=1){
                            pageNum=1;
                            bl_canclick=true;
                        }
                        else{
                            setTimeout(function(){
                                bl_canclick=true;
                            },2500)
                        }
                    }
                    else if(mouseY-mouseAfterY>-50)  {
                        pageNum++;

                        console.log("right");
                        switch (pageNum) {
                            case 2:
                                page1.Out();
                                page2.start();
                                break;
                            case 3:
                                // page2.end();
                                setTimeout(function () {
                                    page3.start();
                                }, 500)
                                break;
                            case 4:
                                // page3.end();
                                setTimeout(function () {
                                    page4.start();
                                }, 500)
                                break;
                            case 5:
                                // page4.end();
                                setTimeout(function () {
                                    page5.start();
                                }, 500)

                                setTimeout(function(){
                                    sc.bl_canMove=true;
                                },2400)
                                break;
                        }
                        if(pageNum>=5){
                            pageNum=5;
                            bl_canclick=true;
                        }
                        else{
                            setTimeout(function(){
                                bl_canclick=true;
                            },2500)
                        }
                    }
                }
            })



        };
        cc.DoIt=function(){
            if(page1) {
                page1.DoIt();
            }
            if(page7) {
                page7.DoIt();
            }
        }

        cc.ReturnWhole=function(){
            return whole;
        };
        return cc;
    }
}
